<template>
  <view>
    <web-view :src="previewUrl" v-if="platform === 'ios'"></web-view>
  </view>
</template>

<script>
export default {
  data() {
    return {
      platform: "",
      previewUrl: "",
      title: "",
    };
  },
  onLoad(options) {
    const that = this;
    this.previewUrl = options.previewUrl;
    uni.setNavigationBarTitle({
      title: options.title,
    });
    uni.getSystemInfo({
      success: function (res) {
        that.platform = res.platform;
        if (res.platform === "android") {
          uni.downloadFile({
            url: that.previewUrl,
            success: function (res) {
              var filePath = res.tempFilePath;
              uni.openDocument({
                filePath: filePath,
                showMenu: true,
                success: function (res) {
                  console.log("打开文档成功");
                },
                fail: function (error) {
                  console.log("打开文档失败", error);
                },
              });
            },
          });
        }
      },
    });
  },
};
</script>

<style></style>
